//
//  StockExchangeJa.m
//  MarketDataAnalyzer
//
//  Created by jiro on 10/01/26.
//  Copyright 2010 jiro music. All rights reserved.
//

#import "StockExchangeJa.h"
#import "../DbConstants.h"
#import "DbUtility.h"

@implementation StockExchangeJa

@synthesize	marketInitial;
@synthesize volume;
@synthesize	adjustedEndPrice;

+ (NSString*) tableName
{
	return kText_StockExchangeJaTable;
}

+ (id) stockExchangeJaWithDbRespose: (NSArray*) values
{
	StockExchangeJa* ret	= [ [ StockExchangeJa alloc ] init ];
	ret.code				= [ values objectAtIndex: 0 ];
	ret.exchangeDate		= [ NSDate dateWithString: [ DbUtility convertIsoStdDateStringToCocoaDateString: [ values objectAtIndex: 1 ] ] ];
	ret.marketInitial		= [ values objectAtIndex: 2 ];
	ret.openPrice			= [ [ values objectAtIndex: 3 ] floatValue ];
	ret.highPrice			= [ [ values objectAtIndex: 4 ] floatValue ];
	ret.lowPrice			= [ [ values objectAtIndex: 5 ] floatValue ];
	ret.closePrice			= [ [ values objectAtIndex: 6 ] floatValue ];
	ret.volume				= [ [ values objectAtIndex: 7 ] floatValue ];
	ret.adjustedEndPrice	= [ [ values objectAtIndex: 8 ] floatValue ];
	return ret;
}

+ (NSString*) queryCreateTable
{
	NSString* s = [ NSString stringWithFormat:
		@"create table %@ ( %@ %@, %@ %@, %@ %@, %@ %@, %@ %@, %@ %@, %@ %@, %@ %@, %@ %@, %@ ( %@, %@, %@ ) );", 
		[ StockExchangeJa tableName ],
		kText_Code, kText_Text,
		kText_ExchangeDate, kText_TimestampWithTimeZone,
		kText_MarketInitial, kText_Text,
		kText_OpenPrice, kText_Real,
		kText_HighPrice, kText_Real,
		kText_LowPrice, kText_Real,
		kText_ClosePrice, kText_Real,
		kText_Volume, kText_Real,
		kText_AdjustedEndPrice, kText_Real,
		kText_PrimaryKey, kText_Code, kText_ExchangeDate, kText_MarketInitial
	];
	return s;
}

- (NSString*) sqlInsertStatement
{
	return [ NSString stringWithFormat: @"insert into %@ values %@;", kText_StockExchangeJaTable, [ self queryInsertValue ] ];
}


+ (NSString*) querySelectAll
{
	NSString* s = [ NSString stringWithFormat: @"select * from %@;", [ StockExchangeJa tableName ] ];
	return s;
}

- (NSString*) queryInsert
{
	NSString* s = [ NSString stringWithFormat: @"insert into * values %@;", 
		[ StockExchangeJa tableName ], [ self queryInsertValue ] ];
	return s;
}

- (NSString*) queryInsertValue
{
	return [ NSString stringWithFormat: @"( '%@', '%@', %f, %f, %f, %f, %f, %f, %f )",
		code, [ exchangeDate description ],  
		openPrice, highPrice, lowPrice, closePrice, volume, adjustedEndPrice ];
}

@end
